#pragma once

#include "effectbase.h"
#include <osg\Vec4>
#include <osg\BoundingBox>
#include <osg\Geode>
#include <osg/NodeCallback>

namespace VrDataCore
{
	class VRDATACORE_EXPORT BoundingBoxEffect:public EffectBase
	{
	public:
		BoundingBoxEffect();
	protected:
		~BoundingBoxEffect();
		osg::ref_ptr<osg::Geode> createBoundingbox(osg::BoundingBox& box,osg::Vec4& color=osg::Vec4(1.0,1.0,0.0,1.0),bool opacity=false);
	public:
		virtual void buildPropertyMap();
		virtual osg::ref_ptr<CoreBase::ActorBase> clone();
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
		void setMaterial(osg::Vec4 material);
		osg::Vec4 getMaterial();
		void update();
	private:
		osg::Vec4								_materialValue;
		bool									_add;
		osg::Vec4								_constMaterial;
		osg::ref_ptr<osg::Geode>				_boundingBoxGeode;
		osg::ref_ptr<osg::Geometry>				_boundingBoxGeometry;
	};

	class BoundingBoxUpdateCallback : public osg::NodeCallback
	{
	public:
		BoundingBoxUpdateCallback(BoundingBoxEffect* bb)
		{
			_bb = bb ;
		}
		~BoundingBoxUpdateCallback(){} ;
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
		{
			if( !_bb )
				return ;
			_bb->update() ;
		}
	protected:
		BoundingBoxEffect *_bb ;
	};
}